#ifndef _MNGCSEAPI_H_CSEAPI_
#define _MNGCSEAPI_H_CSEAPI_

#include "CseApi.h"

#define TManaged(T)                TMngHolder<T>

#ifndef self
  #define self                     (*this)
#endif

#ifndef MNG_OPEN_NEWDEL
  #define MNG_BUFF_BEGIN(AClass,ABase)   \
    private: static void* operator new(size_t); \
      static void* operator new(size_t,int); \
      static void operator delete(void*); \
      static void operator delete(void*,size_t); \
      const AClass* operator&() const; \
    public: \
      AClass(CseObj obj): ABase(obj) { } \
      AClass(const AClass& obj): ABase(obj.m_data) { } \
      class m_ { public:
#else
  #define MNG_BUFF_BEGIN(AClass,ABase)   \
    public: \
      AClass(CseObj obj): ABase(obj) { } \
      AClass(const AClass& obj): ABase(obj.m_data) { } \
      class m_ { public:
#endif

#define MNG_BUFF_END(AClass,ABase)  }; \
    class m: public ABase::m, public m_ { private: m(); m(const m& obj); }; \
    m *operator->() { return (m*) m_data->bValue; } \
    void __init__() { \
        int iLen = sizeof(m) / sizeof(CseObj); \
        if (len() < iLen) resize(iLen); \
        m_ obj; int iLen_ = sizeof(obj) / sizeof(CseObj); \
        CseObj *pSour = (CseObj *) &obj; \
        for (int i = iLen - iLen_; i < iLen; i++,pSour++) sub(i) = *pSour; \
        setExitFunc(METHOD_ADDR(AClass,__exit__)); \
    }

#define PROP_INT(AClass,name)      TIntProp name; static TInt __ ## name(AClass& me,TIntObj& value,TInt* pValue)
#define PROP_WINT(AClass,name)     TWintProp name; static TWint __ ## name(AClass& me,TWintObj& value,TWint* pValue)
#define PROP_FLOAT(AClass,name)    TFloatProp name; static TDouble __ ## name(AClass& me,TFloatObj& value,TDouble* pValue)
#define PROP_STR(AClass,name)      TStrProp name; static TXchar* __ ## name(AClass& me,TCharArray& value,const TXchar** pValue)

#define BIND_PROP(AClass,name)        (*this)->name.bindMethod((void*)this,(void*)&AClass::m_:: __ ## name)
#define PROP_FUNC_INT(AClass,name)    TInt AClass::m_:: __ ## name(AClass& me, TIntObj& value, TInt *pValue) {
#define PROP_FUNC_WINT(AClass,name)   TWint AClass::m_:: __ ## name(AClass& me, TWintObj& value, TWint *pValue) {
#define PROP_FUNC_FLOAT(AClass,name)  TDouble AClass::m_:: __ ## name(AClass& me, TFloatObj& value, TDouble *pValue) {
#define PROP_FUNC_STR(AClass,name)    TXchar* AClass::m_:: __ ## name(AClass& me, TCharArray& value, const TXchar** pValue) {
#define PROP_FUNC_END                 if (pValue != NULL) value = *pValue; return value; }

#endif
